package collection

/**
 * Created by CJJ on 2017/7/14.
 */
fun main(args: Array<String>) {
    collection()
}

fun collection() {
    val intList = mutableListOf(1, 2, 3, 5, 100, 24, 7)
    intList.add(4)
    val set = hashSetOf(1, 3, 5, 2, 17, 4, 7, 6)
    intList.sortBy { l -> l % 2 }
    println(intList)

    chainCalls()
    println(createClosure()(3))
}

fun chainCalls() {
    println("----------chain calls--------------")
    var array = arrayOf(1, 2, 4, 6, 10, 12, 14, 3, 5, 7, 11)
    array.filter { value -> value % 2 == 0 }
            .dropLastWhile { it > 4 }
            .forEach { print("$it \t") }

    println("")

}



//闭包
fun createClosure(): (Int) -> String {
    println("----------closure--------------")

    var a = "inner variable "
    return fun(t: Int): String {

        return a + t
    }

}


fun lock(int: Int) {
    foo()
}

fun foo() {

}